package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.Agent;
import com.example.demo.mapper.AgentMapper;
import com.example.demo.service.AgentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;


@Slf4j
@Service
public class AgentServiceImpl extends ServiceImpl<AgentMapper, Agent> implements AgentService {
    @Override
    public Page<Agent> listAgentsByPage(int page, int pageSize, String company, String education, String profession ) {
        log.info("正在执行分页查询agent: page = {} pageSize = {} company = {} ability={} profession={}", page, pageSize, company, education, profession);

        QueryWrapper<Agent> queryWrapper = new QueryWrapper<Agent>()
                .eq(company.length() != 0, "company", company)
                .eq(education.length() != 0, "education", education)
         //       .eq(profession.length() !=0, "profession",profession);
                .and(profession.length()!=0,wrapper->wrapper.like("profession",profession));

        Page<Agent> result = super.page(new Page<>(page, pageSize), queryWrapper);
        log.info("分页查询agent完毕: 结果数 = {} ", result.getRecords().size());
        return result;
    }

    @Override
    public Agent getById(Integer id) {
        QueryWrapper<Agent> queryWrapper =  new QueryWrapper<Agent>().eq(id != null,"id",id);
        Agent agent = super.getOne(queryWrapper);
        return  agent;
    }
}
